import java.io.*;
import java.util.HashMap;

// setAll功能的哈希表
// 测试链接 : https://www.nowcoder.com/practice/7c4559f138e74ceb9ba57d76fd169967
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code，提交时请把类名改成"Main"，可以直接通过
public class SetAllHashMap {

    public static int setTime;
    public static int setValue;

    public static int cnt;
    public static HashMap<Integer, int[]> map = new HashMap<>();


    public static int n, op, a, b;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        while(in.nextToken() != StreamTokenizer.TT_EOF) {
            map.clear();
            n = (int) in.nval;
            setValue = 0;
            setTime = -1;
            cnt = 0;
            for(int i = 0; i < n; ++i) {
                in.nextToken();
                op = (int) in.nval;
                if (op == 1) {
                    in.nextToken();
                    a = (int) in.nval;
                    in.nextToken();
                    b = (int) in.nval;
                    put(a, b);
                } else if (op == 2) {
                    in.nextToken();
                    a = (int) in.nval;
                    out.println(get(a));
                } else {
                    in.nextToken();
                    a = (int) in.nval;
                    setAll(a);
                }

            }

        }
        out.flush();
        out.close();
        br.close();
    }

    public static void put(int k, int v) {
        if(map.containsKey(k)) {  //存在就修改值
            int[] arr = map.get(k);
            arr[0] = v;
            arr[1] = cnt++;
        }else {
            int[] arr = new int[]{v,cnt++};
            map.put(k,arr);
        }
    }

    public static int get(int k) {
        if(!map.containsKey(k)) {
            return -1;
        }
        int[] arr = map.get(k);
        if(arr[1]  < setTime){
            return setValue;
        } else {
            return arr[0];
        }
    }

    public static void setAll(int v) {
        setValue = v;
        setTime = cnt++;
    }
}
